﻿module Main

open System
open System.Reflection
open System.Threading
open System.Windows
open Wpf
open Spider

let handleClick _ =
        let proj = projName.Text
        let url = inputTxtBox.Text
        let depth = depthTxtBox.Text
        let limit = limitTxtBox.Text
        match proj with
        | "" -> MessageBox.Show("Please enter a project name.") |> ignore
        | _ -> match url with
               | "" -> MessageBox.Show("Please enter a valid URL.") |> ignore
               | _ -> match depth with
                      | "" -> MessageBox.Show("Please specify the crawling depth.") |> ignore
                      | _ -> match limit with
                             | "" -> MessageBox.Show("Please specify the maximum number of URLs to crawl.") |> ignore
                             | _ -> let depth' = 
                                       try
                                           Some <| int depth
                                       with _ -> None
                                    let limit' =
                                        try
                                            Some <| int limit
                                        with _ -> None
                                    match depth' with
                                    | None -> MessageBox.Show("The depth value is invalid.") |> ignore
                                    | Some d -> match limit' with
                                                | None -> MessageBox.Show("The limit value is invalid.") |> ignore
                                                | Some l -> crawl proj url d l
                                               
processUrlBtn.Click |> Event.add handleClick

// Navigate to the first page.
navWind.NavigationService.Navigate page1 |> ignore

ThreadPool.SetMinThreads(10,10) |> ignore
let app = Application()

[<AssemblyVersionAttribute("0.7.*")>]
[<STAThread>]
navWind |> app.Run |> ignore